<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<title>日结管理</title>
		<script type="text/javascript" language="javascript" src="../script/card.js"></script>
		<script type="text/javascript" language="javascript" src="../script/common.js"></script>
		<script type="text/javascript" language="javascript" src="../script/common_stat.js"></script>
		<script type="text/javascript" language="javascript">
			var Page;
			function initPageElements(){
				Page.sql = "daily_check_list";
				Page.crosstab = new Crosstab();
				
				var crossconf = {};
				crossconf.measures = {sum:'交易金额',count:"交易数"};
				crossconf.defaultMeasure = {sum:true,count:true};
				crossconf.dimensions = {accountType:'帐户类型',tradeType:'交易类型',tradeStatus:'交易状态'
										,cardUserType:"客户类型",cardUserLevel:"客户级别",cardType:"卡类型",bank:'银行'};
				crossconf.defaultVertical = {};
				crossconf.defaultHorizon = {accountType:true,tradeType:true,tradeStatus:true};
				Page.pivot = new Pivot("pivot","counter_daily_tx",crossconf,{initPivotHead:initPivotHead,backFunc:goFirstPage});
				Page.pivot.setPivotHead('pivotTitle','发卡充值点日结报表');
				Page.pivot.setPivotHead('statOper',Common.cOperator().name);
				Page.pivot.setPivotHead('statOrg',Common.cOrg().name);
				Page.pivot.setPivotHead("statClass",'日结报表');
				
				Page.selection.status={list:Common.getSubsetItems("daily_status",Clear.DailyCheck.ONLINE_STATUS)
					,nullLabel:"全  部"};
				Page.operation = {title:"操作",
					width:"8%",
					align:"center",
					render:function(v,r){
								return "<a href=# onclick='showStat(\""+Format.dateRender(r[1])+"\");'>日结报表</a>";
							}
				};
			}
			function initPivotHead(div){
				var title = '<table width="100%" border="0" cellspacing="0" cellpadding="5" style="width:600">'
						  + '<tr><td align="center" class="reportTitle" height="50" colspan="2" id="#DIVID#_pivotTitle"></td></tr>'
						  + '<tr><td width="67%">统 计 人：<span id="#DIVID#_statOper"></span></td><td>统计机构：<span id="#DIVID#_statOrg"></span></td></tr>'
						  + '<tr><td>统计时间：<span id="#DIVID#_statTime"></span></td><td>报表类型：<span id="#DIVID#_statClass"></span></td></tr>'
						  + '<tr><td>业务日期：<span id="#DIVID#_businessDate"></span></td><td></td></tr></table>';
				$(div+'_pivot_head').innerHTML = title.replace(/#DIVID#/g,div);
			}
			
			function showStat(date){
				SimulatePos.sendRequest();
				
				var param = {};
				param.orgId = Common.cOrg().id;
				param.businessDate = date;
				Page.pivot.param = param;
				Page.pivot.setPivotHead("statTime",Format.today(true));
				Page.pivot.setPivotHead("businessDate",date);
				Page.pivot.refresh();
				var check = DWR.syncCall("dailyCheckService.getCounterDailyCheck",Common.cOrg().id,date);
				showDailyDetail(check);
				switchPage("detailView");
			}
			function showDailyDetail(check){
				$('confirmBtn').disabled = (check.status==DailyCheckStatus.ONLINE_OK);
				$('confirmBtn').onclick = function(){confirmCheck(check.id);}
				var s = '';
				if (check.status == DailyCheckStatus.ONLINE_INIT){
					s = '尚未日结';
					$('confirmBtn').innerHTML = '确认日结';
				}else{
					s = '日结时间'+Format.timeRender(check.finishTime)+' 总金额(元):'
						+ Format.fenToYuan(check.amount)+' 交易笔数'+check.txCount;
					$('confirmBtn').innerHTML = '重新日结';
				}
				$('dailyCheckDetail').innerHTML = s;
			}
			function confirmCheck(id){
				if(showQuestion("确认日结?")){
					DWR.call("dailyCheckService.doDailyCheck",
							id,
							function(result){
								showDailyDetail(result);
								showInformation("保存成功");
							},
							{blockScreen:true}
						);
				}
			}
			function goFirstPage(){
				switchPage('listView');
				ListPage.showListTable();
			}
		</script>
	</head>
	
	<body onload="TX.List.init()">
		<div class="nav"><div id="nav">&nbsp;</div></div>
		
		<div id="listView" >
			<div class="searchForm">
				<form id='searchForm' name='searchForm'>
					<input type="hidden" name="orgID">
					<table cellSpacing="0" cellPadding="4" width="100%" border="0">
						<tr>
							<td class="label5" id="beginDateTd"></td>	
							<td class="label5" id="endDateTd"></td>
							<td>
								<label>日结状态</label> 
								<select name="status"></select>
							</td>
							<td>
								<button onclick="ListPage.showListTable()">查 询</button>
								<button onclick="showStat(Format.today())">今日日结</button>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div id="datalist"></div>
		</div>
		<div id="detailView" style="display:none">
			<div id="pivot"></div>
			<div class="form">
				<div class="formTitle">日结状态 [<span id="dailyCheckDetail"></span>]</div>
			</div>
			<p>
				<button id="confirmBtn">确认日结</button>
			</p>
		</div>
	</body>
</html>
